package arena.soldier;

import gameframework.game.SpriteManagerDefaultImpl;

import java.awt.Canvas;
import java.awt.Graphics;
import java.awt.Point;
import java.awt.Rectangle;

public class GhostMonster extends SoldierAbstract {
	private static final int FORCE = 5;
	private static final int HEALTHPOINTS = 100;
	
	protected boolean movable = true;
	protected boolean active = true;
	private final SpriteManagerDefaultImpl spriteManager;
	public static final int RENDERING_SIZE = 36;

	public GhostMonster(String nom, Canvas defaultCanvas) {
		super(nom, HEALTHPOINTS, FORCE);
		spriteManager = new SpriteManagerDefaultImpl("images/ghost.gif",
				defaultCanvas, RENDERING_SIZE, 6);
		spriteManager.setTypes(
				//
				"left",
				"right",
				"up",
				"down",//
				"beginAfraid-left",
				"beginAfraid-right",
				"beginAfraid-up",
				"beginAfraid-down", //
				"endAfraid-left", "endAfraid-right",
				"endAfraid-up",
				"endAfraid-down", //
				"inactive-left", "inactive-right", "inactive-up",
				"inactive-down", //
				"unused");
	}
	
	public void heal() { //XXX resurrection allowed
		healthPoints = HEALTHPOINTS;
	}
	
	public boolean isActive() {
		return active;
	}

	public void setAlive(boolean aliveState) {
		active = aliveState;
	}
	
	@Override
	public void draw(Graphics g) {
		String spriteType = "";
		Point tmp = getSpeedVector().getDirection();
		movable = true;

		if (!isActive()) {
			spriteType = "inactive-";
		}

		if (tmp.getX() == -1) {
			spriteType += "left";
		} else if (tmp.getY() == 1) {
			spriteType += "down";
		} else if (tmp.getY() == -1) {
			spriteType += "up";
		} else {
			spriteType += "right";
		}

		spriteManager.setType(spriteType);
		spriteManager.draw(g, getPosition());
	}

	@Override
	public Rectangle getBoundingBox() {
		return (new Rectangle(0, 0, RENDERING_SIZE, RENDERING_SIZE));
	}

	@Override
	public void oneStepMoveAddedBehavior() {
		if (movable) {
			spriteManager.increment();
		}
	}

	@Override
	public SpriteManagerDefaultImpl getSpriteManager() {
		return spriteManager;
	}
	@Override
	public float getHealthPointAtBeginning() {
		return HEALTHPOINTS;

	}

	@Override
	public float getMagic() {
		return 0;
	}

	@Override
	public float getMagicAtBeginning() {
		return 0;
	}

	@Override
	public boolean isEnrage() {

		return false;
	}

	@Override
	public void setEnrage(int timer) {
	}
}		